<template>
  <div class="index-container">
    <el-table v-loading="listLoading" :data="list">
      <el-table-column
        align="center"
        label="商品ID"
        prop="id"
        show-overflow-tooltip
        width="70"
      />

      <el-table-column
        align="center"
        label="商品名称"
        prop="goods_name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="商品类型"
        prop="type_name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="商品分组"
        prop="method_name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="商品价格"
        prop="goods_price"
        show-overflow-tooltip
      />

      <el-table-column
        align="center"
        label="划线价"
        prop="goods_cost"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="销量"
        prop="sales_volume"
        show-overflow-tooltip
      />

      <el-table-column
        align="center"
        label="上架时间"
        prop="created_at"
        show-overflow-tooltip
        width="200"
      />

      <template #empty>
        <el-empty class="vab-data-empty" description="暂无数据" />
      </template>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.page"
      :layout="layout"
      :page-size="queryForm.page_size"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </div>
</template>
<script>
  export default defineComponent({
    name: 'FollowsLogs',
    setup() {
      const state = reactive({
        list: [],
        total: 0,
        listLoading: false,
        layout: 'total, sizes, prev, pager, next, jumper',
        queryForm: {
          page: 1,
          page_size: 10,
        },
      })
      const followsData = async () => {
        state.listLoading = true
        const {
          data: { data, total },
        } = await getList(state.queryForm)
        state.list = data
        state.total = total
        state.listLoading = false
      }

      const handleSizeChange = (val) => {
        state.queryForm.page_size = val
        followsData()
      }
      const handleCurrentChange = (val) => {
        state.queryForm.page = val
        followsData()
      }

      const showList = () => {
        followsData()
      }

      onMounted(() => {
        followsData()
      })

      return {
        ...toRefs(state),
        followsData,
        showList,
        handleSizeChange,
        handleCurrentChange,
      }
    },
  })
</script>
